﻿using NHibernate;
using NHibernate.Cfg;
using Search4.Domain.Entity;
using System;

namespace Search4.Domain.Repository
{
    public class EnderecoRepository
    {
        private ISessionFactory sessionFactory = new Configuration()
                        .Configure()
                        .BuildSessionFactory();

        public void Salvar(Endereco endereco)
        {
            using (var session = sessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.SaveOrUpdate(endereco);
                session.Transaction.Commit();
                session.Flush();
            }
        }

        public Endereco ObterPeloIdentificador(Int32 id)
        {
            using (var session = sessionFactory.OpenSession())
            {
                return session.Get<Endereco>(id);
            }
        }
    }
}
